package com.stars.easyms.alarm.service;

import com.stars.easyms.alarm.client.EasyMsAlarmClient;
import com.stars.easyms.alarm.message.EasyMsAlarmMessage;
import com.stars.easyms.base.asynchronous.BaseAsynchronousTask;

import java.util.List;

/**
 * <p>className: EasyMsAsynAlarmService</p>
 * <p>description: EasyMs实现的异步告警服务类</p>
 *
 * @author guoguifang
 * @version 1.6.3
 * @date 2020/9/19 10:45 上午
 */
public class EasyMsAsynAlarmService extends BaseAsynchronousTask<EasyMsAlarmMessage> {

    private final List<EasyMsAlarmClient> alarmClientList;

    public EasyMsAsynAlarmService(List<EasyMsAlarmClient> alarmClientList) {
        this.alarmClientList = alarmClientList;
    }

    @Override
    protected boolean execute(EasyMsAlarmMessage alarmMessage) {
        for (EasyMsAlarmClient alarmClient : alarmClientList) {
            try {
                alarmClient.sendAlarmMessage(alarmMessage);
            } catch (Exception e) {
                logger.error("Easy-ms {} alarm client send message fail!", alarmClient.getClientType(), e);
            }
        }
        return true;
    }
}
